<template>
	<!-- 瑞再风险筛查 -->
	<!-- 待处理事项模块-影像列表 -->
	<div class="fillcontain">
		<el-dialog title="PowerView" :visible.sync="drawer" :width="'50%'" :before-close="handleClose" center>
			<!-- <div class="contain"> -->
			<!-- 表格 -->
			<div class="contain">
				<el-row class="mt10">
					<el-col :span="8">
						<el-button class="check-info " @click="callRz('N')" :disabled="item.procflg >= 4">发起PowerView调用</el-button>
					</el-col>
				</el-row>
				<div style="height: 50%;overflow-y: auto;">
					<el-row class="mt10" style="border-top: 1px solid #e1e1e1 !important;">
						<el-form label-width="100px" class="search_container">
							<el-row>
								<el-col :span="12" class="common-box">
									<el-form-item label="风险等级">
										<span>{{rz.riskLevel}}</span>
									</el-form-item>
								</el-col>
								<el-col :span="12" class="common-box">
									<el-form-item label="风险评分">
										<span>{{rz.srModelScore}}</span>
									</el-form-item>
								</el-col>
							</el-row>
							<el-row>
								<el-col :span="12" class="common-box">
									<el-form-item label="最大风险保额">
										<span>{{rz.maxSA}}</span>
									</el-form-item>
								</el-col>
								<el-col :span="12" class="common-box">
									<el-form-item label="核保结论">
										<span>{{rz.resultComment}}</span>
									</el-form-item>
								</el-col>
							</el-row>
						</el-form>
					</el-row>
				</div>

			</div>
		</el-dialog>
	</div>
</template>
<script>
	import moment from 'moment';
	import constant from '@/utils/constant';
	import TaskConstants, {
		call
	} from "@/api/taskManager/common";
	export default {
		data() {
			return {
				rz: {
					"riskLevel": '',
					"srModelScore": '',
					"maxSA": '',
					"resultComment": ''
				},
				emptyRz: '', //缓存空的
            }
		},
		props: {
			drawer: {
				type: Boolean,
				default: false
			},
			item: {
				type: Object,
				default: {}
			},
		},
		watch: {
			item: function(newValue) {
				if(undefined != newValue){
					this.callRz('Y');
				}
			}
		},
		created() {
			this.emptyRz = JSON.parse(JSON.stringify(this.rz));
		},
		methods: {
			show() {
				this.$store.dispatch('loading/CHANGE_LOADING', true);
			},
			cancle() {
				this.$store.dispatch('loading/CHANGE_LOADING', false)
			},
			handleClose(done) {
			  this.$emit('close', this.drawer);
			},
			callRz(onlyQuery) {
				let body = {
					 "type": "ciitc_power_view",
					 "sysFrom": "S10003",
					 "userCode": "citic",
					 "queryFlag":"Y",
					 "userName": "统一核保平台",
					 "datetime": moment().format('YYYYMMDD HH:mm:ss'),
					 "swiftNumber": moment().format('YYYYMMDDHHmmsssSSSSSSSSS'),
				}
                let benefit = {
                    "productCode": this.item.productCode,
					"benefitCode": this.item.benefitCode,
					"benefitType": this.item.benefitType,
					"benefitAmt": parseInt(this.item.benefitAmt) + ''
                }
                let userInfo = {
                    "policyNum": this.item.policyNum,
				    "customerId": this.item.customerId,
				    "idType": this.item.idType,
				    "identity": this.item.identity,
				    "name": this.item.name,
				    "phone": this.item.phone,
				    "gender": this.item.gender,
				    "birthday": this.item.birthday,
				    "benefits": []
                }
                userInfo.benefits.push(benefit);
				let params = {
					"ciitc_power_view": {
                        "onlyQuery": onlyQuery,
						"interfaceScene": "riskScore",
			            "locationCode": this.item.locationCode + '',
			            "useCase": "BAUW",
                        "policies": []
					}
				};
                params['ciitc_power_view'].policies.push(userInfo);
				body['reqBody'] = params;
				//清空之前的
				this.rz = JSON.parse(JSON.stringify(this.emptyRz));
				let that = this;
				that.show();
				call(TaskConstants.apis.rzQuery, body, "post").then(result => {
					if (result.resultCode == constant.SUCCESS && result.data && result.data.length>0) {
						let ciitc_power_view = result.data[0]['ciitc_power_view'];
						if(ciitc_power_view.status == '200') {
							let data = ciitc_power_view.data.policies[0];
							Object.keys(this.rz).forEach(function(key, index) {
								let v = data[key];
								if(key == 'riskLevel') {
									switch(v) {
										case 'Low':
											v = '1-低风险';
											break;
										case 'Medium':
											v = '2-中风险';
											break;
										case 'High':
											v = '3-高风险';
											break;
										case 'NotFound':
											v = '4-未击中';
											break;
										default:
											v = ''
									}
								}
                            	that.rz[key] = v;
							})
						}
					}
					that.cancle();
				})
			}
		}
	}
</script>
<style lang="less" scoped>
	.fillcontain {
		padding-bottom: 0;
	}

	.contain {
		background: #fff;
		// padding: 10px;
		margin-bottom: 20px;
	}

	.pagination {
		padding: 10px 20px;
		text-align: right;
	}

	.operationIcon {
		// padding: 12px;
		border: 1px solid #e5e5e5;
		border-radius: 50%;
		width: 22px;
		height: 22px;
		display: inline-block;
		cursor: pointer;
		box-shadow: 0 0 3px #f9f9f9;

		.svg-icon {
			font-size: 14px;
			fill: #68a3fc;
		}
	}

	.search_container {
		padding: 20px 20px 0 20px;
		// border-top: 1px solid #e1e1e1;
	}
</style>
